package cn.main.entity.sys;



import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Set;
import java.util.UUID;


/**
 * Author: chengwei
 * Date:   2016/5/12
 * Time:   10:36
 */
@Entity
@Table(name ="sys_function")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class SysFunction implements Serializable {
    private static final long serialVersionUID = 1723552402014410385L;
    @Id
    @Column(name = "function_id")
    private String  functionId ;
    @Column
    private String name;

    @Column(name = "is_public")
    private boolean aPublic;
    
    @Column(name = "is_jsp")
    private boolean isJsp;
    
    @Column(name = "url")
    private String url;

    @Column(name = "show_order")
    private String showOrder;
    
    @ManyToOne
    @JoinColumn(name = "column_id")
    private SysColumn column;
    
    @ManyToMany(mappedBy = "functions")
    private Set<Role> roles; 
    
    
    
    public SysFunction(String functionId, String name) {
        this.functionId = functionId;
        this.name = name;
    }

    public SysFunction() {
        
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getFunctionId() {
        if (functionId == null || functionId.equals("")) {
            functionId = UUID.randomUUID().toString().replace("-","");
        }
        return functionId;
    }

    public void setFunctionId(String functionId) {
        this.functionId = functionId;
    }

    public SysColumn getColumn() {
        return column;
    }

    public void setColumn(SysColumn column) {
        this.column = column;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    public boolean isaPublic() {
        return aPublic;
    }

    public void setaPublic(boolean aPublic) {
        this.aPublic = aPublic;
    }

    public boolean isJsp() {
        return isJsp;
    }

    public void setJsp(boolean jsp) {
        isJsp = jsp;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(String showOrder) {
        this.showOrder = showOrder;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        SysFunction that = (SysFunction) o;

        return getFunctionId().equals(that.getFunctionId());

    }

    @Override
    public int hashCode() {
        return getFunctionId() != null ? getFunctionId().hashCode() : 0;
    }
}
